package io;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * 对象流
 * java.io.ObjectOutputStream和ObjectInputStream
 * 对象流是一对高级流，作用是进行对象序列化与反序列化
 * 对象序列化：将java对象按照其结构和内容转换为一组字节的过程，反之为对象反序列化
 */
public class OOSDemo {
    public static void main(String[] args) throws IOException {
        String name = "海绵宝宝";
        int age = 8;
        String gender = "男";
        String[] otherInfo={"在水里","可爱","黄色海绵"};
        Person p = new Person(name,age,gender,otherInfo);
        System.out.println(p);
        //将person对象写入文件person.obj中
        FileOutputStream fos = new FileOutputStream("person.obj");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(p);
        System.out.println("学出完毕");
        oos.close();
    }
}
